package com.app.configuration;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @create 2020-11-19 21:14
 * 配置fill
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        //用户的fill insert
        this.setFieldValByName("userCreatedate", new Date(), metaObject);
        this.setFieldValByName("userUpdatedate", new Date(), metaObject);
        //聊一聊的fill insert
        this.setFieldValByName("consultCreatedate", new Date(), metaObject);
        this.setFieldValByName("consultUpdatedate", new Date(), metaObject);
        //投诉/反馈的fill insert
        this.setFieldValByName("compliantCreatedate", new Date(), metaObject);
        this.setFieldValByName("compliantUpdatedate", new Date(), metaObject);
        //订单的fill insert
        this.setFieldValByName("ordersCreateTime", new Date(), metaObject);
        this.setFieldValByName("ordersModifyTime", new Date(), metaObject);
        //收藏的fill insert
        this.setFieldValByName("collectCreateTime", new Date(), metaObject);
        this.setFieldValByName("collectModifyTime", new Date(), metaObject);

    }

    @Override
    public void updateFill(MetaObject metaObject) {
        //用户的fill update
        this.setFieldValByName("userUpdatedate", new Date(), metaObject);
        //聊一聊的fill update
        this.setFieldValByName("consultUpdatedate", new Date(), metaObject);
        //投诉/反馈的fill update
        this.setFieldValByName("compliantUpdatedate", new Date(), metaObject);
        //订单的fill update
        this.setFieldValByName("ordersModifyTime", new Date(), metaObject);
        //收藏的fill update
        this.setFieldValByName("collectModifyTime", new Date(), metaObject);
    }
}
